package com.ysd.lis.service.qi.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.qi.QiIndexSqlBusiness;
import com.ysd.lis.mapper.qi.QiIndexSqlBusinessMapper;
import com.ysd.lis.service.qi.QiIndexSqlBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * sql业务中间表 服务实现类
 * </p>
 *
 * @author WH
 * @since 2024-07-10
 */
@Service
public class QiIndexSqlBusinessServiceImpl extends ServiceImpl<QiIndexSqlBusinessMapper, QiIndexSqlBusiness> implements QiIndexSqlBusinessService {

    @Autowired
    QiIndexSqlBusinessMapper qiIndexSqlBusinessMapper;
    @Override
    public Result addQiIndexSqlBusiness(QiIndexSqlBusiness qiIndexSqlBusiness) {
        boolean save = this.save(qiIndexSqlBusiness);
        if (save) {
            return Result.succ(1, "", null);
        } else {
            return Result.fail("添加失败！");
        }
    }

    @Override
    public Result findQiIndexSqlBusinessList(QiIndexSqlBusiness pageParam) {

        MPJLambdaWrapper<QiIndexSqlBusiness> mpjLambdaWrapper = new MPJLambdaWrapper<>();
        mpjLambdaWrapper.selectAll(QiIndexSqlBusiness.class)
                .eq(QiIndexSqlBusiness::getDelFlag, 0)
                .eq(QiIndexSqlBusiness::getModuleType, pageParam.getModuleType())
                .eq(QiIndexSqlBusiness::getIndexCode,pageParam.getIndexCode())
                .eq(QiIndexSqlBusiness::getItemCode, pageParam.getItemCode())
                .eq(QiIndexSqlBusiness::getMajorCode,pageParam.getMajorCode())
                .orderByAsc(QiIndexSqlBusiness::getCreateTime);
        List<QiIndexSqlBusiness> list = qiIndexSqlBusinessMapper.selectList(mpjLambdaWrapper);
        return Result.succ(list);
    }

    @Override
    public Result deleteQiIndexSqlBusiness(QiIndexSqlBusiness deleteParam) {
        int i = qiIndexSqlBusinessMapper.deleteById(deleteParam.getId());
        if (i > 0) {
            return Result.succ(1, "移除成功", null);
        } else {
            return Result.fail("移除失败！");
        }
    }
}
